/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.arthurh.android.BdeInfo.connection;
import com.arthurh.android.BdeInfo.*;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.view.Display;
import android.widget.TextView;
import android.widget.LinearLayout;
import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.Toast;
import android.widget.ProgressBar;
import android.widget.EditText;
import android.content.Context;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

/**
 *
 * @author arthur
 */
public class Inscription extends Activity{
    private Connection conn;
    private String idIut;
    private String pass;
    private String prenom;
    private String nom;
    private String mail;
    private Context context;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        
        super.onCreate(savedInstanceState);
        this.setTitle("BdeInfo - Inscription");
        setContentView(R.layout.inscription);
        
        
        conn = new Connection();
        
        context = this.getBaseContext();
        ((Button)findViewById(R.id.envoyer)).setOnClickListener(new OnClickListener() {
            
            @Override
            public void onClick(View v) {
                pass = ((EditText) findViewById(R.id.passInscri)).getText().toString();
                prenom = ((EditText) findViewById(R.id.prenom)).getText().toString();
                idIut = ((EditText) findViewById(R.id.idIutInscri)).getText().toString();
                nom = ((EditText) findViewById(R.id.nom)).getText().toString();
                mail = ((EditText) findViewById(R.id.mail)).getText().toString();
                boolean error = false;
                if(prenom.equals("")){
                    Toast.makeText(context, "Prénom vide !" ,Toast.LENGTH_SHORT).show();
                    error = true;
                }
                if(nom.equals("")){
                    Toast.makeText(context, "Nom vide !" ,Toast.LENGTH_SHORT).show();
                    error = true;
                }
                if(mail.equals("")){
                    Toast.makeText(context, "Mail vide !" ,Toast.LENGTH_SHORT).show();
                    error = true;
                }
                if(idIut.equals("")){
                    Toast.makeText(context, "Identifiant IUT vide !" ,Toast.LENGTH_SHORT).show();
                    error = true;
                }
                if(pass.equals("")){
                    Toast.makeText(context, "Mot de passe vide !" ,Toast.LENGTH_SHORT).show();
                    error = true;
                }
                if(!error){
                    if(conn.inscription(prenom, nom,
                            mail, idIut, pass, context) ){
                        Toast.makeText(context, "Inscription réussi !" ,Toast.LENGTH_SHORT).show();
                        finish();

                    }else{

                    }
                }
                
            }
        });
    }
}
